//封装mysql的方法
import mysql from "mysql";

let conn = mysql.createConnection({
    host: "127.0.0.1", //链接远程服务器
    user: "root",
    password: "",
    port: 3306,
    database: "yangguangnet"
})

//简单的封装
let exec = function (sql, params, callback) {
    conn.query(sql, params, callback);
}

let execAsync = function (sql, params) {
    return new Promise(function (resolve, reject) {
        conn.query(sql, params, (err, row, fields) => {
            if (err) {
                console.log("有错误", err.message);
                reject(err.message);
                return;
            }
            resolve(row)
        });
    })
}

//暴露
module.exports = {
    exec,
    execAsync
}